package view;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.GridLayout;

import javax.swing.BorderFactory;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingConstants;

import model.player.Player;


public class InformationPanel extends JPanel {
	
	private static final long serialVersionUID = 1L;
	
	private InfoPanelThread _infoPanelThread = new InfoPanelThread();
	
	private Player _player;
	
	JLabel labelLives = new JLabel();
	
	JLabel labelScore = new JLabel();
	
	JLabel labelWave = new JLabel();
	
	JLabel labelMoney = new JLabel();
	
	
	public InformationPanel(Player player) {
		
		this.setBackground(Color.BLACK);
		this.setPreferredSize(new Dimension(190, 40));
		this.setBorder(BorderFactory.createLineBorder(Color.gray));
		this.setLayout(new GridLayout(2, 2));
		
		_player = player;
		_init();
	}
	
	
	private void _init() {
		
		labelLives.setForeground(Color.WHITE);
		labelScore.setForeground(Color.WHITE);
		labelWave.setForeground(Color.WHITE);
		labelMoney.setForeground(Color.WHITE);
		labelLives.setHorizontalAlignment(SwingConstants.CENTER);
		labelScore.setHorizontalAlignment(SwingConstants.LEFT);
		labelWave.setHorizontalAlignment(SwingConstants.CENTER);
		labelMoney.setHorizontalAlignment(SwingConstants.LEFT);
		
		this.add(labelWave);
		this.add(labelScore);
		this.add(labelLives);
		this.add(labelMoney);
		_infoPanelThread.start();
	}
	
	
	public void paintComponent(Graphics g) {
		
		super.paintComponent(g);
		
		labelLives.setText("Lives : "+_player.lives);
		labelScore.setText("Score : "+_player.score);
		labelWave.setText("Wave : 1/2");
		labelMoney.setText("Money : 0");
	}
	
	
	
	class InfoPanelThread extends Thread {

		public void run() {
			while(true) {
				try {
					repaint();
					sleep( 10 );
				} catch ( Exception e ) {} 
			}
		}
	}
	
}
